/*
 * Copyright 2010 - Jeremie Brebec
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.jb.sharedbills.shared.model;

import org.jb.sharedbills.shared.model.notification.AbstractNotifier;

public class Member extends AbstractNotifier {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8391272366285730988L;
	private String name;
	private int count = 1;
	private double maxAmount = 0;
	private double used = 0;
	
	/**
	 * 
	 */
	public Member() {
		
	}
	
	/**
	 * 
	 * @param name
	 */
	public Member( String name ) {
		setName( name );
	}
	
	/**
	 * 
	 * @param count
	 */
	public void setCount(int count) {
		if (count != this.count) {
			int oldcount = count;
			this.count = count;
			doNotify( "count", oldcount, count );
		}
	}
	
	/**
	 * 
	 * @return
	 */
	public int getCount() {
		return count;
	}

	/**
	 * 
	 * @param maxAmount
	 */
	public void setMaxAmount(double maxAmount) {
		if (maxAmount != this.maxAmount) {
			double oldmaxAmount = this.maxAmount;
			this.maxAmount = maxAmount;
			doNotify( "maxAmount", oldmaxAmount, maxAmount );
		}
	}

	/**
	 * 
	 * @return
	 */
	public double getMaxAmount() {
		return maxAmount;
	}
	
	/**
	 * 
	 * @param used
	 */
	public void setUsed(double used) {
		if (used != this.used) {
			double oldused = this.used;
			this.used = used;
			doNotify( "used", oldused, this.used );
		}
	}

	/**
	 * 
	 * @return
	 */
	public double getUsed() {
		return used;
	}

	/**
	 * 
	 * @return
	 */
	public double getBalance() {
		return maxAmount - used;
	}

	/**
	 * 
	 * @param name
	 */
	public void setName( String name ) {
		if (this.name == null || !this.name.equals(name)) {
			String oldName = this.name;
			this.name = name;
			doNotify( "name", oldName, this.name );
		}
	}
	
	/**
	 *
	 */
	public String getName() {
		return name;
	}
}
